CREATE PROCEDURE [dbo].[Projects]
	-- Add the parameters for the stored procedure here
	
AS
BEGIN
	
	DECLARE @statusidActive int;
	DECLARE @statusidOver int ;
	SELECT @statusidActive=ID from projectstatus where statusname='Active';
	SELECT @statusidOver=ID from projectstatus where statusname='Over';
	
	DECLARE project_cur  cursor for select [id],[projectenddate],[projectstatusid] from project where [projectstatusid]=@statusidActive;
	declare @statusid int ;
	declare @enddate datetime;
	declare @id int; 
	open project_cur
	fetch next from project_cur into @id ,@enddate,@statusid;
	while @@FETCH_STATUS=0
	begin
	if DATEDIFF(DAY,GETDATE(),@enddate) <0
	update project set [projectstatusid]=@statusidOver where [id]=@id;
	fetch next from project_cur into @id ,@enddate,@statusid;
	END;
	close project_cur;
	deallocate project_cur;
END
